    var add = document.getElementById('add');
    var box = document.getElementById('box');
    var id = '';
    add.onclick = function () {
        box.style.display = 'block';
    }
    //添加操作函数
    function addData() {
        
        //获取表单数据
        var name = document.addForm.name.value;
        var sex = document.addForm.sex.value;
        var age = document.addForm.age.value;
        var grade = document.addForm.grade.value;
        
        //创建请求对象
        var xhr = new XMLHttpRequest();

        //事件
        xhr.onreadystatechange = function (){
            if (xhr.status == 200 && xhr.readyState == 4) {
                if (xhr.responseText > 0) { 
                   alert('修改成功!!');
                   location.href='./index.php?c=User&a=index';
                    //加载新的一行
                    var tr = table.insertRow(table.rows.length);
                    tr.insertCell(0).innerHTML = xhr.responseText;
                    tr.insertCell(1).innerHTML = name;
                    tr.insertCell(2).innerHTML = sex;
                    tr.insertCell(3).innerHTML = age;
                    tr.insertCell(4).innerHTML = grade;
                } else{
                    alert('添加失败...');
                    location.href='./index.php?c=User&a=index';
                }
            }
        }

        xhr.open('post', './index.php?c=User&a=insert', true);
        //设置请求头
        xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
        xhr.send('name='+name+'&sex='+sex+'&age='+age+'&grade='+grade);

        return false;
    }



    //删除操作
    function del(id) {
         //创建请求对象
        var xhr = new XMLHttpRequest();
         //事件
        xhr.onreadystatechange = function (){
            if (xhr.status == 200 && xhr.readyState == 4) {
                if (xhr.responseText > 0) { 
                   alert('删除成功!!');
                   location.href='./index.php?c=User&a=index';
                } else{
                    alert('删除失败...');
                    location.href='./index.php?c=User&a=index';
                }
            }
        }
        xhr.open('get', './index.php?c=User&a=del&id='+id, true);
        xhr.send();

    }

    //修改操作
    function editData() {
        //获取数据
        var id = document.addForm.id.value;
        var name = document.addForm.name.value;
        var sex = document.addForm.sex.value;
        var age = document.addForm.age.value;
        var grade = document.addForm.grade.value;
        //创建请求对象
        var xhr = new XMLHttpRequest();
         //事件
        xhr.onreadystatechange = function (){
            if (xhr.responseText > 0) { 
               alert('修改成功!!');
               location.href='./index.php?c=User&a=index';
            } else{
                alert('修改失败...');
                location.href='./index.php?c=User&a=index';
            }
        }
        xhr.open('post', './index.php?c=User&a=updt', true);
        xhr.send('id='+id+'&name='+name+'&sex='+sex+'&age='+age+'&grade='+grade);

         return false;   
    }



